package cn.jy.map.service.impl;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jy.map.domain.AddressJwdMsg;
import cn.jy.map.domain.AddressMsg;
import cn.jy.map.domain.AllGjzCollSituation;
import cn.jy.map.domain.AllGjzCollSituation.GjzAllType;
import cn.jy.map.domain.AllGjzCollSituation.GjzChildType;
import cn.jy.map.domain.AllGjzCollSituation.ThisYearGjzType;
import cn.jy.map.domain.GjzDzJwd;
import cn.jy.map.domain.GjzLc;
import cn.jy.map.domain.JzJyDz;
import cn.jy.map.domain.LcCondition;
import cn.jy.map.domain.ProviderBaseInfo;
import cn.jy.map.domain.ProviderType;
import cn.jy.map.domain.RegisterGtt;
import cn.jy.map.domain.VillageColligate;
import cn.jy.map.domain.XyDmRounds;
import cn.jy.map.mapper.GjzAllTypeMapper;
import cn.jy.map.mapper.GjzDzJwdMapper;
import cn.jy.map.mapper.GjzLcMapper;
import cn.jy.map.mapper.GjzxxMapper;
import cn.jy.map.mapper.RegisterGttMapper;
import cn.jy.map.mapper.VillageColligateMapper;
import cn.jy.map.service.GjzDzJwdService;
import cn.jy.map.utils.GjzType;
import cn.jy.map.utils.MapUtils;
import cn.jy.nvr.datasource.DataSourceConst;
import cn.jy.nvr.datasource.DataSourceContextHolder;

@Service("gjzDzJwdService")
public class GjzDzJwdServiceImpl implements GjzDzJwdService {
	
	@Autowired
	RegisterGttMapper registerGttMapper;
	@Autowired
	GjzxxMapper gjzxxMapper;
	@Autowired
	GjzDzJwdMapper gjzDzJwdMapper;
	@Autowired
	GjzLcMapper gjzLcMapper;
	@Autowired
	GjzAllTypeMapper gjzAllTypeMapper;
	@Autowired
	VillageColligateMapper villageColligateMapper;

	Logger logger = Logger.getLogger(GjzDzJwdServiceImpl.class);
	private JzJyDz jzJyDz;
	/**
	 * 装载供浆者经纬度数据，在服务器启动的时候装载一次
	 */
	@Override
	public void loadGjzDzJwdData(){
		
		ProviderBaseInfo pbif = new ProviderBaseInfo();
//		pbif.setFileDate("2017-09-28 00:00:00");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<ProviderBaseInfo> gjzList = gjzxxMapper.getAllProviderBaseInfo(pbif);
		
		logger.info("待装载的供浆者经纬度数据的供浆者条数："+gjzList.size());
		if(gjzList != null && gjzList.size()>0){
			logger.info("开始装载供浆者经纬度数据~~~");
			
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			for(ProviderBaseInfo baseInfo : gjzList){
				String address = baseInfo.getAddress();
				
				List<String> addList = splitAddress(address);
				
				getJzJyDzByAddress(null, null, addList);
				
				GjzDzJwd jwd = new GjzDzJwd();
				jwd.setID(UUID.randomUUID().toString());
				jwd.setPROVIDERNO(baseInfo.getProviderNo());
				jwd.setCARDNO(baseInfo.getIDNo());
				jwd.setNAME(baseInfo.getName());
				jwd.setGENDER(baseInfo.getSex());
				jwd.setBIRTHDAY(baseInfo.getBirthDay());
				jwd.setFILEDATE(baseInfo.getFileDate());
				jwd.setADDRESS(baseInfo.getAddress());
				jwd.setPROVIDERSTATE(baseInfo.getProviderState());
				if(jzJyDz != null){
					jwd.setNATIVEPLACE(jzJyDz.getPATH().replace(".", ""));
					jwd.setGX(jzJyDz.getGX());
					jwd.setGY(jzJyDz.getGY());
					jwd.setCODE(jzJyDz.getCODE());
				}
				
				gjzDzJwdMapper.addGjzDzJwd(jwd);
				
				jzJyDz = null;
				
				logger.info("装载【"+jwd+"】成功~~");
				
			}
			
			logger.info("装载供浆者经纬度数据结束~~~");
		}
		
		
		
		
	}
	
	private void getJzJyDzByAddress(String path,String name,List<String> addList){
		
		if(addList != null && addList.size()>0){
			if(path == null && name == null){
				//证明是第一次传进来
				path = "%";
				for(String address : addList){
					path += address+"%";
				}
				name = addList.get(addList.size()-1);
			}
			
			List<JzJyDz> dzList = gjzxxMapper.getJzJyDzByAddress(path, name);
			
			if(dzList.size() == 0){
				addList.remove(addList.size() - 1);
				path = "%";
				for(String address : addList){
					path += address+"%";
				}
				if(addList.size()>0){
					name = addList.get(addList.size()-1);
				}
				getJzJyDzByAddress(path, name, addList);
			}else{
				jzJyDz = dzList.get(0);
			}
		}
		
	}
	
	
	private List<String> splitAddress(String address){
		int sheng = address.indexOf("省");
		int shi = address.indexOf("市");
		int diqu = address.indexOf("地区");
		int zzz = address.indexOf("自治州");
		int xian = address.indexOf("县");
		int zhen = address.indexOf("镇");
		int xiang = address.indexOf("乡");
		int cun = address.indexOf("村");
		int jie = address.indexOf("街");
		int xiangzi = address.indexOf("巷");
		
		String sheng_ = "";
		String diqu_ = "";
		String zzz_ = "";
		String shi_ = "";
		String xian_ = "";
		String zhen_ = "";
		String xiang_ = "";
		String cun_ = "";
		String jie_ = "";
		String xiangzi_ = "";
		
		try {
			if(cun > 0){
				//有村，就用乡/镇来截取是什么村
				if(zhen > 0 ){
					cun_ = address.substring(zhen + 1, cun + 1);
				}else if(xiang > 0){
					cun_ = address.substring(xiang + 1, cun + 1);
				}else if(xian > 0){
					cun_ = address.substring(xian + 1, cun + 1);
				}else if(shi > 0){
					cun_ = address.substring(shi + 1, cun + 1);
				}else if(sheng > 0){
					cun_ = address.substring(sheng + 1, cun + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(jie > 0){
				if(zhen > 0 ){
					jie_ = address.substring(zhen + 1, jie + 1);
				}else if(xiang > 0){
					jie_ = address.substring(xiang + 1, jie + 1);
				}else if(xian > 0){
					jie_ = address.substring(xian + 1, jie + 1);
				}else if(shi > 0){
					jie_ = address.substring(shi + 1, jie + 1);
				}else if(sheng > 0){
					jie_ = address.substring(sheng + 1, jie + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		
		try {
			if(xiangzi > 0){
				if(zhen > 0 ){
					xiangzi_ = address.substring(zhen + 1, xiangzi + 1);
				}else if(xiang > 0){
					xiangzi_ = address.substring(xiang + 1, xiangzi + 1);
				}else if(xian > 0){
					xiangzi_ = address.substring(xian + 1, xiangzi + 1);
				}else if(shi > 0){
					xiangzi_ = address.substring(shi + 1, xiangzi + 1);
				}else if(sheng > 0){
					xiangzi_ = address.substring(sheng + 1, xiangzi + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(xiang > 0){
				if(xian > 0){
					xiang_ = address.substring(xian + 1, xiang + 1);
				}else if(shi > 0){
					xiang_ = address.substring(shi + 1, xiang + 1);
				}else if(sheng > 0){
					xiang_ = address.substring(sheng + 1, xiang + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(zhen > 0){
				if(xian > 0){
					zhen_ = address.substring(xian + 1, zhen + 1);
				}else if(shi > 0){
					zhen_ = address.substring(shi + 1, zhen + 1);
				}else if(sheng > 0){
					zhen_ = address.substring(sheng + 1, zhen + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(xian > 0){
				if(shi > 0){
					xian_ = address.substring(shi + 1, xian + 1);
				}else if(diqu > 0){
					xian_ = address.substring(diqu + 2, xian + 1);
				}else if(sheng > 0){
					xian_ = address.substring(sheng + 1, xian + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(shi > 0){
				if(sheng > 0){
					shi_ = address.substring(sheng + 1, shi + 1);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(diqu > 0){
				if(sheng > 0){
					diqu_ = address.substring(sheng + 1, diqu) + "市";
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(zzz > 0){
				if(sheng > 0){
					zzz_ = address.substring(sheng + 1, zzz + 3);
				}
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		try {
			if(sheng > 0){
				sheng_ = address.substring(0, sheng + 1);
			}
		} catch (Exception e) {
			logger.error("截取地址【"+address+"】时出错："+e);
		}
		
		List<String> addList = new ArrayList<String>();
		if(!"".equals(sheng_)){
			addList.add(addList.size(), sheng_);
		}
		if(!"".equals(shi_)){
			addList.add(addList.size(), shi_);
		}
		if(!"".equals(diqu_)){
			addList.add(addList.size(), diqu_);
		}
		if(!"".equals(zzz_)){
			addList.add(addList.size(), zzz_);
		}
		if(!"".equals(xian_)){
			addList.add(addList.size(), xian_);
		}
		if(!"".equals(zhen_)){
			addList.add(addList.size(), zhen_);
		}
		if(!"".equals(xiang_)){
			addList.add(addList.size(), xiang_);
		}
		if(!"".equals(cun_)){
			addList.add(addList.size(), cun_);
		}
		if(!"".equals(jie_)){
			addList.add(addList.size(), jie_);
		}
		if(!"".equals(xiangzi_)){
			addList.add(addList.size(), xiangzi_);
		}
		
		return addList;
	}
	
	private List<AddressMsg> getDzJwdList(){
		BufferedReader br = null;
		List<AddressMsg> ams = new ArrayList<AddressMsg>();
		try {


			String str = null;
			// File f = new FileReader("",)
			// new FileReader("D:\\jzgl\\dz_jwd.txt");
			Reader reader = new InputStreamReader(new FileInputStream("D:\\jzgl\\dz_jwd.txt"), "utf-8");
			br = new BufferedReader(reader);

			str = br.readLine();

			while (str != null && !"".equals(str)) {

				String[] strArr = str.split(",");
				List<String> value = new ArrayList<String>();
				value.add(strArr[1]);
				value.add(strArr[0]);
				value.add(((int) (Math.random() * 300)) + "");

				AddressMsg am = new AddressMsg();
				am.setName(strArr[2]);
				am.setValue(value);
				ams.add(am);

				str = br.readLine();
			}

			logger.info(ams);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (br != null) {
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

		return ams;
	}
	
	
	@Override
	public List<AddressMsg> getDzJwdList(String code,String date,String isRegist,String lookBeginGjz) {
		
		List<AddressJwdMsg> aList = null;
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		if("1".equals(lookBeginGjz)){
			if(date != null && !"".equals(date)){
				date = MapUtils.forMatDate(date);
			}else{
				date = MapUtils.getNowOnlyDateFomat2();
			}
			
			//先获取这个时间的这天第一个体检浆员的时间
			Map<String, Date> mbMap = gjzDzJwdMapper.getMinBodyCheckTime(date);
			
			Date minBodyCheckTime = null;
			if(mbMap != null){
				minBodyCheckTime = mbMap.get("minBodyCheckTime");
			}
			if(minBodyCheckTime == null || "".equals(minBodyCheckTime)){
				//如果没有查询到体检的时间，就获取登记的时间+20分钟
				mbMap = gjzDzJwdMapper.getMinRegistTime(date);
				if(mbMap != null){
					minBodyCheckTime = mbMap.get("minRegistTime");
				}
			}
			if(minBodyCheckTime != null && !"".equals(minBodyCheckTime)){
				aList = gjzDzJwdMapper.getRegistBetweenBodyCheck(date, MapUtils.formatDate(minBodyCheckTime));
			}
			
		}else{
			if("1".equals(isRegist)){
				if(date != null && !"".equals(date)){
					date = MapUtils.forMatDate(date);
				}else{
					date = MapUtils.getNowOnlyDateFomat2();
				}
				aList = gjzDzJwdMapper.getRegist(date);
				
			}else{
//				logger.info("---------"+MapUtils.allForgeProviderNoStr);
				if(date != null && !"".equals(date)){
					date = MapUtils.forMatDate(date);
					aList = gjzDzJwdMapper.getAddressJwdMsg(date,MapUtils.allForgeProviderNoStr);
				}else{
					List<AddressMsg> list = MapUtils.allGjzJwdMap.get("gjzType0");
					return list;
				}
			}
		}
		
		
		List<AddressMsg> ams = new ArrayList<AddressMsg>();
		int temp = 0;
		if(aList != null){
			logger.info("待查询的所有地区的经纬度和浆员总量列表："+aList.size());
			for(AddressJwdMsg ajm : aList){
				List<String> value = new ArrayList<String>();
				value.add(ajm.getJd());
				value.add(ajm.getWd());
				value.add(ajm.getCount()+"");
				temp += ajm.getCount();
				AddressMsg am = new AddressMsg();
				am.setName(ajm.getName());
				am.setValue(value);
				am.setVillageColligate(MapUtils.allVillageColligate.get(ajm.getName()));
				ams.add(am);
			}
		}
		System.out.println("--------------------------------"+temp);
		return ams;
	}

	@Override
	public List<RegisterGtt> getRetisterGtt(String address,String date,String isNew) throws Exception {
		
		if(address != null && !"".equals(address)){
			logger.info("待查询的登记甘特图地址："+address);
			if(date != null && !"".equals(date)){
				date = MapUtils.forMatDate(date);
			}else{
				date = MapUtils.getNowOnlyDateFomat2();
			}
			
			if(!"1".equals(isNew)){
				isNew = "0";
			}
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			List<RegisterGtt> rList = registerGttMapper.getRegisterGttListByAddr(address,date,isNew);
			logger.info(rList);
			return rList;
		}
		logger.info("待查询的登记甘特图地址为Null");
		return null;
	}

	@Override
	public List<GjzLc> getJijGjzLc(String address, String date)
			throws Exception {
		if(address != null && !"".equals(address)){
			if(date != null && !"".equals(date)){
				
			}else{
				date = MapUtils.getNowOnlyDateFomat1();
			}
			logger.info("获取地区【"+address+"】下面的【"+date+"】积极浆员登记的轮次表");
			date = MapUtils.forMatDate(date);
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			//先获取这个时间的这天第一个体检浆员的时间
			Map<String, Date> mbMap = gjzDzJwdMapper.getMinBodyCheckTime(date);
			
			Date minBodyCheckTime = null;
			if(mbMap != null){
				minBodyCheckTime = mbMap.get("minBodyCheckTime");
			}
			if(minBodyCheckTime == null || "".equals(minBodyCheckTime)){
				//如果没有查询到体检的时间，就获取登记的时间+20分钟
				mbMap = gjzDzJwdMapper.getMinRegistTime(date);
				if(mbMap != null){
					minBodyCheckTime = mbMap.get("minRegistTime");
				}
			}
			List<GjzLc> list = new ArrayList<GjzLc>();
			if(minBodyCheckTime != null && !"".equals(minBodyCheckTime)){
				list = gjzLcMapper.getJijRegGjzLcByAddress(date, address, MapUtils.formatDate(minBodyCheckTime));
			}
			return list;
		}
		logger.info("地址为null，获取轮次表失败！");
		return null;
	}

	@Override
	public List<RegisterGtt> getJijRetisterGtt(String address, String date) {
		if(address != null && !"".equals(address)){
			logger.info("待查询的登记甘特图地址："+address);
			if(date != null && !"".equals(date)){
				date = MapUtils.forMatDate(date);
			}else{
				date = MapUtils.getNowOnlyDateFomat2();
			}
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);

			//先获取这个时间的这天第一个体检浆员的时间
			Map<String, Date> mbMap = gjzDzJwdMapper.getMinBodyCheckTime(date);
			
			Date minBodyCheckTime = null;
			if(mbMap != null){
				minBodyCheckTime = mbMap.get("minBodyCheckTime");
			}
			if(minBodyCheckTime == null || "".equals(minBodyCheckTime)){
				//如果没有查询到体检的时间，就获取登记的时间+20分钟
				mbMap = gjzDzJwdMapper.getMinRegistTime(date);
				if(mbMap != null){
					minBodyCheckTime = mbMap.get("minRegistTime");
				}
			}
			List<RegisterGtt> rList = new ArrayList<RegisterGtt>();
			if(minBodyCheckTime != null && !"".equals(minBodyCheckTime)){
				rList = registerGttMapper.getJijRegisterGttListByAddr(address,date, MapUtils.formatDate(minBodyCheckTime));
			}
			logger.info(rList);
			return rList;
		}
		logger.info("待查询的登记甘特图地址为Null");
		return null;
	}

	@Override
	public String getThisRound() {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<XyDmRounds> rounds = gjzLcMapper.getXyDmRounds(MapUtils.getNowOnlyDateFomat1());
		if(rounds != null && rounds.size()>0){
			return rounds.get(0).getRID();
		}
		
		return null;
	}

	@Override
	public AllGjzCollSituation getAllGjzCollSituation(String date) {
		logger.info("获取所有供浆者的采浆情况");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		AllGjzCollSituation agcs = new AllGjzCollSituation();
		
		LoadAllGjzCollData ld = new LoadAllGjzCollData();
		if(date == null || "".equals(date)){
			date = MapUtils.getNowOnlyDateFomat1();
		}
		ld.loadComed(agcs, date);
		ld.getZcjy(agcs, date);
		ld.getFuSujy(agcs, date);
		ld.getNewGjz(agcs, date);
		ld.getXiuMianjy(agcs, date);
		ld.getLiuShijy(agcs, date);
		
		return agcs;
	}
	
	private class LoadAllGjzCollData{
		
		/**
		 * 加载今年已经来过的  和 今年没来过的 浆员的基本信息
		 */
		public void loadComed(AllGjzCollSituation agcs,String date){
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			if(agcs == null){
				agcs = new AllGjzCollSituation();
			}
			
			//得到指定日期的年份
			String thisYear = MapUtils.getThatYear(date);//指定日期的当前年份
			
			//gjzAllTypeMapper.getAllPlasmaProviderNum(MapUtils.getCurrentYear());//获取某一年的采浆的浆员数量
			Map<String, Integer> map = gjzAllTypeMapper.getAllPlasmaGrossByYear(date,thisYear);//获取某一年采的总浆量

			Map<String, Integer> allNum = gjzAllTypeMapper.getCountProviderNum(date);//获取指定日期前建档的所有浆员的数量和这个日期前这些浆员的采浆量
			
			Integer allProviderNum = allNum.get("NUM");
			if(allProviderNum == null){
				allProviderNum = 0;
			}
			Integer allCollNum = allNum.get("SUMCOLLNUM");
			if(allCollNum == null){
				allCollNum = 0;
			}
			Integer sumGjzNum = map.get("NUM");
			if(sumGjzNum == null){
				sumGjzNum = 0;
			}
			Integer sumCollNum = map.get("SUMCOLLNUM");
			if(sumCollNum == null){
				sumCollNum = 0;
			}
			
			//设置总浆量和总的浆员数
			agcs.setSumGjzNum(allProviderNum);
			agcs.setSumCollNum(allCollNum);
			
			
			float zhanbi = (Float.valueOf(sumGjzNum+"")/Float.valueOf(allProviderNum +"")) * 100f;
			
			zhanbi = (float)(Math.round(zhanbi*100))/100;//Float.valueOf( String.format("%.2f", zhanbi));
			
			ThisYearGjzType gjzT1 = agcs.getThisYearComedGjz();
			ThisYearGjzType gjzT2 = agcs.getThisYearNotComed();
			if(gjzT1 == null){
				gjzT1 = new AllGjzCollSituation.ThisYearGjzType();
			}
			if(gjzT2 == null){
				gjzT2 = new AllGjzCollSituation.ThisYearGjzType();
			}
			//今年来过的
			gjzT1.setSumGjzNum(sumGjzNum);
			gjzT1.setSumCollNum(sumCollNum);
			gjzT1.setZhanBi(zhanbi);
			
			//今年没来过的
			gjzT2.setSumGjzNum(allProviderNum - sumGjzNum); 
			gjzT2.setSumCollNum(0);
			gjzT2.setZhanBi(100f - zhanbi);
			
			agcs.setThisYearComedGjz(gjzT1);
			agcs.setThisYearNotComed(gjzT2);
			
		}
		
		/**
		 * 获取指定日期前的忠诚浆员
		 * @param agcs
		 * @param date ：选定的日期，获取的数据都是这个日期之前的
		 * 
		 * 去年建档的，在去年来献过浆的并且在今年也来献过浆的
		 */
		public void getZcjy(AllGjzCollSituation agcs,String date){
		
			//忠诚浆员：去年来了，今年也来了的
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			
			//得到指定日期的年份
			String thisYear = MapUtils.getThatYear(date);//指定日期的当前年份
			//获取指定日期的上一年的年份
			String lastYear = MapUtils.getThatYear(thisYear,-1);//指定日期的当前年份的上一年
			
			
			//获取总的忠诚浆员
			Map<String, Integer> azbd = gjzAllTypeMapper.getAllZcjyBeforeDate(date, thisYear, lastYear);
			ThisYearGjzType gjzT1 = agcs.getThisYearComedGjz();//今年来过的
//			ThisYearGjzType gjzT2 = agcs.getThisYearNotComed();//今年没来过的
			
			GjzAllType zcGjz = gjzT1.getZcGjz();//忠诚供浆者
			
			if(zcGjz == null){
				zcGjz = new GjzAllType();
			}
			int zcSumGjzNum = 0;
			int zcSumCollNum = 0;
			if(azbd.get("NUM") != null){
				zcSumGjzNum = azbd.get("NUM");
			}
			if(azbd.get("SUMCOLLNUM") != null){
				zcSumCollNum = azbd.get("SUMCOLLNUM");
			}
			
			zcGjz.setSumGjzNum(zcSumGjzNum);
			zcGjz.setSumCollNum(zcSumCollNum);
			
			int sumGjzNumComed = gjzT1.getSumGjzNum();
			
			float zhanbi = (Float.valueOf(zcSumGjzNum+"")/Float.valueOf(sumGjzNumComed +"")) * 100f;
			zhanbi = (float)(Math.round(zhanbi*100))/100;//Float.valueOf( String.format("%.2f", zhanbi));
			zcGjz.setZhanBi(zhanbi);
			
			float zhanbiAll = (Float.valueOf(zcSumGjzNum+"")/Float.valueOf(agcs.getSumGjzNum() +"")) * 100f;
			zhanbiAll = (float)(Math.round(zhanbiAll*100))/100;//Float.valueOf( String.format("%.2f", zhanbiAll));
			zcGjz.setZhanBiAll(zhanbiAll);
			
			//获取忠诚浆员下面的所有类型
			//去年新人：指定日期上一年新人
			setChildType(agcs, zcGjz, date, thisYear, lastYear, lastYear, zcSumGjzNum, sumGjzNumComed,1,1);
			//前年新人：指定日期前两年新人
			String createYear = MapUtils.getThatYear(thisYear,-2);
			setChildType(agcs, zcGjz, date, thisYear, lastYear, createYear, zcSumGjzNum, sumGjzNumComed,2,1);
			
			//大前年新人
			createYear = MapUtils.getThatYear(thisYear,-3);
			setChildType(agcs, zcGjz, date, thisYear, lastYear, createYear, zcSumGjzNum, sumGjzNumComed,3,1);
			
			//大前年之前的新人
			setChildType(agcs, zcGjz, date, thisYear, lastYear, createYear, zcSumGjzNum, sumGjzNumComed,4,1);
			
			gjzT1.setZcGjz(zcGjz);
			
		}
		
		/**
		 * 设置浆员的子类型
		 * @param agcs
		 * @param zcGjz
		 * @param date
		 * @param thisYear
		 * @param lastYear
		 * @param createYear
		 * @param zcSumGjzNum
		 * @param sumGjzNumComed
		 * @param type
		 * @param gjzType ：供浆者类型：忠诚 1、复苏 2 、休眠 3 、流失 4
		 */
		private void setChildType(AllGjzCollSituation agcs,GjzAllType zcGjz,String date,String thisYear,
				String lastYear,String createYear,int zcSumGjzNum ,int sumGjzNumComed,int type,int gjzType){
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			String flag = null;
			if(type == 4){
				flag = "1";
			}
			Map<String, Integer> map = null;
			switch (gjzType) {
			case 1:
				map = gjzAllTypeMapper.getCondition_01(date, thisYear, lastYear,createYear,flag);
				break;
			case 2:
				map = gjzAllTypeMapper.getCondition_02(date, thisYear, lastYear,createYear,flag);
				break;
			case 3:
				map = gjzAllTypeMapper.getCondition_03(date, thisYear, lastYear,createYear,flag);
				break;
			default:
				map = gjzAllTypeMapper.getCondition_04(date, thisYear, lastYear,createYear,flag);
				break;
			}
			
			Integer providerNum = map.get("NUM");//浆员数量
			Integer sumCollNum = map.get("SUMCOLLNUM");//总的献浆次数
			
			if(providerNum == null){
				providerNum = 0;
			}
			if(sumCollNum == null){
				sumCollNum = 0;
			}
			
			float zhanbi_1 = (Float.valueOf(providerNum+"")/Float.valueOf(zcSumGjzNum +"")) * 100f;//占所有忠诚浆员的比例
			zhanbi_1 = (float)(Math.round(zhanbi_1*100))/100;
//			zhanbi_1 = Float.valueOf( String.format("%.2f", zhanbi_1));
			float zhanbi_2 = (Float.valueOf(providerNum+"")/Float.valueOf(sumGjzNumComed +"")) * 100f;//占今年来过的浆员的比例
			zhanbi_2 = (float)(Math.round(zhanbi_2*100))/100;//Float.valueOf( String.format("%.2f", zhanbi_2));
			float zhanbi_3 = (Float.valueOf(providerNum+"")/Float.valueOf(agcs.getSumGjzNum() +"")) * 100f;//占所有浆员的比例
			zhanbi_3 = (float)(Math.round(zhanbi_3*100))/100;//Float.valueOf( String.format("%.2f", zhanbi_3));
			
			
			GjzChildType allChildByYear = zcGjz.getAllChildByYear();
			if(allChildByYear == null){
				allChildByYear = new GjzChildType();
			}
			Map<String, Object> childType = null;
			switch (type) {
			case 1:
				childType = allChildByYear.getLast1YearNewGjz();
				break;
			case 2:
				childType = allChildByYear.getLast2YearNewGjz();
				break;
			case 3:
				childType = allChildByYear.getLast3YearNewGjz();
				break;
			default:
				childType = allChildByYear.getLastNYearNewGjz();
				break;
			}
			
			childType.put("providerNum", providerNum);
			childType.put("sumCollNum", sumCollNum);
			childType.put("zhanbi01", zhanbi_1);
			childType.put("zhanbi02", zhanbi_2);
			childType.put("zhanbi03", zhanbi_3);
			
			switch (type) {
			case 1:
				allChildByYear.setLast1YearNewGjz(childType);
				break;
			case 2:
				allChildByYear.setLast2YearNewGjz(childType);
				break;
			case 3:
				allChildByYear.setLast3YearNewGjz(childType);
				break;
			default:
				allChildByYear.setLastNYearNewGjz(childType);
				break;
			}
			zcGjz.setAllChildByYear(allChildByYear);
		}
		
		
		
		/**
		 * 获取指定日期前的复苏浆员：去年没来，今年来了的浆员
		 * @param agcs
		 * @param date ：选定的日期，获取的数据都是这个日期之前的
		 * 
		 * 去年建档的，在去年来献过浆的并且在今年也来献过浆的
		 */
		public void getFuSujy(AllGjzCollSituation agcs,String date){
			
			//获取指定日期前的所有复苏浆员的数量和采浆总次数
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			//得到指定日期的年份
			String thisYear = MapUtils.getThatYear(date);//指定日期的当前年份
			//获取指定日期的上一年的年份
			String lastYear = MapUtils.getThatYear(thisYear,-1);//指定日期的当前年份的上一年
			Map<String, Integer> fuSu = gjzAllTypeMapper.getCountFuSu(date, thisYear, lastYear);
			
			ThisYearGjzType gjzT1 = agcs.getThisYearComedGjz();//今年来过的
			
			GjzAllType fsGjz = gjzT1.getFsGjz();
			if(fsGjz == null){
				fsGjz = new GjzAllType();
			}
			
			int fsSumGjzNum = 0;
			int fsSumCollNum = 0;
			if(fuSu.get("NUM") != null){
				fsSumGjzNum = fuSu.get("NUM");
			}
			if(fuSu.get("SUMCOLLNUM") != null){
				fsSumCollNum = fuSu.get("SUMCOLLNUM");
			}
			
			fsGjz.setSumGjzNum(fsSumGjzNum);
			fsGjz.setSumCollNum(fsSumCollNum);
			
			int sumGjzNumComed = gjzT1.getSumGjzNum();
			
			float zhanbi = (Float.valueOf(fsSumGjzNum+"")/Float.valueOf(sumGjzNumComed +"")) * 100f;
			zhanbi = (float)(Math.round(zhanbi*100))/100;//Float.valueOf( String.format("%.2f", zhanbi));
			fsGjz.setZhanBi(zhanbi);
			
			float zhanbiAll = (Float.valueOf(fsSumGjzNum+"")/Float.valueOf(agcs.getSumGjzNum() +"")) * 100f;
			zhanbiAll = (float)(Math.round(zhanbiAll*100))/100;//Float.valueOf( String.format("%.2f", zhanbiAll));
			fsGjz.setZhanBiAll(zhanbiAll);
			
			
			//获取复苏浆员的子类型、
			
			//获取忠诚浆员下面的所有类型
			//去年新人：指定日期上一年新人
			setChildType(agcs, fsGjz, date, thisYear, lastYear, lastYear, fsSumGjzNum, sumGjzNumComed,1,2);
			//前年新人：指定日期前两年新人
			String createYear = MapUtils.getThatYear(thisYear,-2);
			setChildType(agcs, fsGjz, date, thisYear, lastYear, createYear, fsSumGjzNum, sumGjzNumComed,2,2);
			
			//大前年新人
			createYear = MapUtils.getThatYear(thisYear,-3);
			setChildType(agcs, fsGjz, date, thisYear, lastYear, createYear, fsSumGjzNum, sumGjzNumComed,3,2);
			
			//大前年之前的新人
			setChildType(agcs, fsGjz, date, thisYear, lastYear, createYear, fsSumGjzNum, sumGjzNumComed,4,2);
			gjzT1.setFsGjz(fsGjz);
		}
		
		/**
		 * 获取指定日期前的休眠浆员：去年来了，今年没来的浆员
		 * @param agcs
		 * @param date ：选定的日期，获取的数据都是这个日期之前的
		 * 
		 * 去年建档的，在去年来献过浆的并且在今年也来献过浆的
		 */
		public void getXiuMianjy(AllGjzCollSituation agcs,String date){
			
			//获取指定日期前的所有复苏浆员的数量和采浆总次数
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			//得到指定日期的年份
			String thisYear = MapUtils.getThatYear(date);//指定日期的当前年份
			//获取指定日期的上一年的年份
			String lastYear = MapUtils.getThatYear(thisYear,-1);//指定日期的当前年份的上一年
			Map<String, Integer> xiuMian = gjzAllTypeMapper.getCountXiuMian(date, thisYear, lastYear);
			
			ThisYearGjzType gjzT1 = agcs.getThisYearNotComed();//今年未来过的浆员
			
			GjzAllType xmGjz = gjzT1.getXmGjz();
			if(xmGjz == null){
				xmGjz = new GjzAllType();
			}
			
			int xmSumGjzNum = 0;
			int xmSumCollNum = 0;
			if(xiuMian.get("NUM") != null){
				xmSumGjzNum = xiuMian.get("NUM");
			}
			if(xiuMian.get("SUMCOLLNUM") != null){
				xmSumCollNum = xiuMian.get("SUMCOLLNUM");
			}
			
			xmGjz.setSumGjzNum(xmSumGjzNum);
			xmGjz.setSumCollNum(xmSumCollNum);
			
			int sumGjzNumComed = gjzT1.getSumGjzNum();
			
			float zhanbi = (Float.valueOf(xmSumGjzNum+"")/Float.valueOf(sumGjzNumComed +"")) * 100f;
			zhanbi = (float)(Math.round(zhanbi*100))/100;//Float.valueOf( String.format("%.2f", zhanbi));
			xmGjz.setZhanBi(zhanbi);
			
			float zhanbiAll = (Float.valueOf(xmSumGjzNum+"")/Float.valueOf(agcs.getSumGjzNum() +"")) * 100f;
			zhanbiAll = (float)(Math.round(zhanbiAll*100))/100;//Float.valueOf( String.format("%.2f", zhanbiAll));
			xmGjz.setZhanBiAll(zhanbiAll);
			
			
			//获取复苏浆员的子类型、
			
			//获取忠诚浆员下面的所有类型
			//去年新人：指定日期上一年新人
			setChildType(agcs, xmGjz, date, thisYear, lastYear, lastYear, xmSumGjzNum, sumGjzNumComed,1,3);
			//前年新人：指定日期前两年新人
			String createYear = MapUtils.getThatYear(thisYear,-2);
			setChildType(agcs, xmGjz, date, thisYear, lastYear, createYear, xmSumGjzNum, sumGjzNumComed,2,3);
			
			//大前年新人
			createYear = MapUtils.getThatYear(thisYear,-3);
			setChildType(agcs, xmGjz, date, thisYear, lastYear, createYear, xmSumGjzNum, sumGjzNumComed,3,3);
			
			//大前年之前的新人
			setChildType(agcs, xmGjz, date, thisYear, lastYear, createYear, xmSumGjzNum, sumGjzNumComed,4,3);
			gjzT1.setXmGjz(xmGjz);
		}
		
		/**
		 * 获取指定日期前的流失浆员：去年、今年都没来的浆员
		 * @param agcs
		 * @param date ：选定的日期，获取的数据都是这个日期之前的
		 * 
		 * 去年建档的，在去年来献过浆的并且在今年也来献过浆的
		 */
		public void getLiuShijy(AllGjzCollSituation agcs,String date){
			
			//获取指定日期前的所有复苏浆员的数量和采浆总次数
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			//得到指定日期的年份
			String thisYear = MapUtils.getThatYear(date);//指定日期的当前年份
			//获取指定日期的上一年的年份
			String lastYear = MapUtils.getThatYear(thisYear,-1);//指定日期的当前年份的上一年
			Map<String, Integer> liushi = gjzAllTypeMapper.getCountLiuShi(date, thisYear, lastYear);
			
			ThisYearGjzType gjzT1 = agcs.getThisYearNotComed();//今年未来过的浆员
			
			GjzAllType lsGjz = gjzT1.getLsGjz();
			if(lsGjz == null){
				lsGjz = new GjzAllType();
			}
			
			int lsSumGjzNum = 0;
			int lsSumCollNum = 0;
			if(liushi.get("NUM") != null){
				lsSumGjzNum = liushi.get("NUM");
			}
			if(liushi.get("SUMCOLLNUM") != null){
				lsSumCollNum = liushi.get("SUMCOLLNUM");
			}
			
			lsGjz.setSumGjzNum(lsSumGjzNum);
			lsGjz.setSumCollNum(lsSumCollNum);
			
			int sumGjzNumComed = gjzT1.getSumGjzNum();
			
			float zhanbi = (Float.valueOf(lsSumGjzNum+"")/Float.valueOf(sumGjzNumComed +"")) * 100f;
			zhanbi = (float)(Math.round(zhanbi*100))/100;//Float.valueOf( String.format("%.2f", zhanbi));
			lsGjz.setZhanBi(zhanbi);
			
			float zhanbiAll = (Float.valueOf(lsSumGjzNum+"")/Float.valueOf(agcs.getSumGjzNum() +"")) * 100f;
			zhanbiAll = (float)(Math.round(zhanbiAll*100))/100;//Float.valueOf( String.format("%.2f", zhanbiAll));
			lsGjz.setZhanBiAll(zhanbiAll);
			
			
			//获取复苏浆员的子类型、
			
			//获取忠诚浆员下面的所有类型
			//去年新人：指定日期上一年新人
			setChildType(agcs, lsGjz, date, thisYear, lastYear, lastYear, lsSumGjzNum, sumGjzNumComed,1,4);
			//前年新人：指定日期前两年新人
			String createYear = MapUtils.getThatYear(thisYear,-2);
			setChildType(agcs, lsGjz, date, thisYear, lastYear, createYear, lsSumGjzNum, sumGjzNumComed,2,4);
			
			//大前年新人
			createYear = MapUtils.getThatYear(thisYear,-3);
			setChildType(agcs, lsGjz, date, thisYear, lastYear, createYear, lsSumGjzNum, sumGjzNumComed,3,4);
			
			//大前年之前的新人
			setChildType(agcs, lsGjz, date, thisYear, lastYear, createYear, lsSumGjzNum, sumGjzNumComed,4,4);
			gjzT1.setLsGjz(lsGjz);
		}
		
		
		
		public void getNewGjz(AllGjzCollSituation agcs,String date){
			ThisYearGjzType gjz = agcs.getThisYearComedGjz();
			GjzAllType newGjz = gjz.getNewGjz();
			if(newGjz == null){
				newGjz = new GjzAllType();
			}
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			//得到指定日期的年份
			String thisYear = MapUtils.getThatYear(date);//指定日期的当前年份
			
			Map<String, Integer> newGjzMap = gjzAllTypeMapper.getNewGjzByDate(date, thisYear);
			
			int sumGjzNum = 0;
			int sumCollNum = 0;
			if(newGjzMap.get("NUM") != null){
				sumGjzNum = newGjzMap.get("NUM");
			}
			if(newGjzMap.get("SUMCOLLNUM") != null){
				sumCollNum = newGjzMap.get("SUMCOLLNUM");
			}
			
			
			newGjz.setSumGjzNum(sumGjzNum);
			newGjz.setSumCollNum(sumCollNum);
			
			
			float zhanbi = (Float.valueOf(sumGjzNum+"")/Float.valueOf(gjz.getSumGjzNum() +"")) * 100f;
			zhanbi =(float)(Math.round(zhanbi*100))/100;// Float.valueOf( String.format("%.2f", zhanbi));
			newGjz.setZhanBi(zhanbi);
			
			float zhanbiAll = (Float.valueOf(sumGjzNum+"")/Float.valueOf(agcs.getSumGjzNum() +"")) * 100f;
			zhanbiAll = (float)(Math.round(zhanbiAll*100))/100;//Float.valueOf( String.format("%.2f", zhanbiAll));
			newGjz.setZhanBiAll(zhanbiAll);
			
			gjz.setNewGjz(newGjz);
		}
		
		
	}
	


	@Override
	public List<AddressMsg> getAllGjzDzJwdBySituation(int gjzType, String date) {
		
		List<String> list = null;
		
		switch (gjzType) {
		case 0:
			list = MapUtils.allTypeGjzMap.get(GjzType.allGjz);
			break;
		case 1:
			list = MapUtils.allTypeGjzMap.get(GjzType.zhongChengGjz);
			break;
		case 2:
			list = MapUtils.allTypeGjzMap.get(GjzType.fuSuGjz);//gjzAllTypeMapper.getfsJy(date, thisYear, lastYear);
			break;
		case 3:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearCreated);//gjzAllTypeMapper.getNewJy(date, thisYear, lastYear);
			break;
		case 4:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianGjz);//gjzAllTypeMapper.getXmJy(date, thisYear, lastYear);
			break;
		case 5:
			list = MapUtils.allTypeGjzMap.get(GjzType.liuShiGjz);//gjzAllTypeMapper.getLsJy(date, thisYear, lastYear);
			break;
		case 6:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianBeConnect);// gjzAllTypeMapper.getLjJy("1");//休眠中已链接
			break;
		case 7:
			list = MapUtils.allTypeGjzMap.get(GjzType.notConnect);//gjzAllTypeMapper.getLjJy(null);//未链接
			break;
		case 8:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearComed);//gjzAllTypeMapper.getThisYearComed(date,thisYear,"1");//今年进站的人
			break;
		case 9:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearNotComed);//gjzAllTypeMapper.getThisYearComed(date,thisYear,null);//今年未进站的人
			break;
		case 10:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianNotConnect);//休眠中未链接
			break;

		default:
			break;
		}
		
		if(list != null){
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			List<AddressJwdMsg> aList = new ArrayList<AddressJwdMsg>();
			if(list.size() > 2000){
				int num = list.size() / 2000 + 1;
				for(int i=0;i < num;i++){
					int toIndex = 2000 * i + 2000;
					if(toIndex > list.size()){
						toIndex = list.size();
					}
					List<String> subList = list.subList(2000 * i, toIndex);
					
					List<AddressJwdMsg> tempList = gjzDzJwdMapper.getAddJwdByProviderNo(subList);
					aList.addAll(tempList);
				}
				
			}else{
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				aList = gjzDzJwdMapper.getAddJwdByProviderNo(list);
			}
			
			List<AddressMsg> ams = new ArrayList<AddressMsg>();
			if(aList != null){
				logger.info("待查询的指定浆员的经纬度和浆员总量列表："+aList.size());
				Map<String,AddressJwdMsg> map = new HashMap<String,AddressJwdMsg>();
				for(AddressJwdMsg ajm : aList){
					
					if(map.get(ajm.getName()) != null){
						AddressJwdMsg msg = map.get(ajm.getName());
						msg.setCount(msg.getCount() + ajm.getCount());
					}else{
						map.put(ajm.getName(), ajm);
					}
				}
				Collection<AddressJwdMsg> values = map.values();
				
				for(AddressJwdMsg ajm : values){
					List<String> value = new ArrayList<String>();
					value.add(ajm.getJd());
					value.add(ajm.getWd());
					value.add(ajm.getCount()+"");
					
					AddressMsg am = new AddressMsg();
					am.setName(ajm.getName());
					am.setValue(value);
					am.setVillageColligate(MapUtils.allVillageColligate.get(ajm.getName()));
					ams.add(am);
					
				}
			}
			return ams;
			
		}
		
		return null;
	}
	
	@Override
	public Map<String ,List<AddressMsg>> getAllGjzDzJwdBySituation(String date) {
		return MapUtils.allGjzJwdMap;
	}

	@Override
	public List<GjzLc> getGjzLcBySituation(int gjzType, String date,
			String address) {

		List<String> list = null;
		
		switch (gjzType) {
		case 1:
			list = MapUtils.allTypeGjzMap.get(GjzType.zhongChengGjz);
			break;
		case 2:
			list = MapUtils.allTypeGjzMap.get(GjzType.fuSuGjz);//gjzAllTypeMapper.getfsJy(date, thisYear, lastYear);
			break;
		case 3:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearCreated);//gjzAllTypeMapper.getNewJy(date, thisYear, lastYear);
			break;
		case 4:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianGjz);//gjzAllTypeMapper.getXmJy(date, thisYear, lastYear);
			break;
		case 5:
			list = MapUtils.allTypeGjzMap.get(GjzType.liuShiGjz);//gjzAllTypeMapper.getLsJy(date, thisYear, lastYear);
			break;
		case 6:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianBeConnect);// gjzAllTypeMapper.getLjJy("1");//休眠中已链接
			break;
		case 7:
			list = MapUtils.allTypeGjzMap.get(GjzType.notConnect);//gjzAllTypeMapper.getLjJy(null);//未链接
			break;
		case 8:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearComed);//gjzAllTypeMapper.getThisYearComed(date,thisYear,"1");//今年进站的人
			break;
		case 9:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearNotComed);//gjzAllTypeMapper.getThisYearComed(date,thisYear,null);//今年未进站的人
			break;
		case 10:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianNotConnect);//休眠中未链接
			break;
		default:
			break;
		}
		
		if(list != null){
			
			//除开废弃浆员
			list.removeAll(MapUtils.allForgeProviderNo);
			
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			List<GjzLc> aList = new ArrayList<GjzLc>();
			if(list.size() > 2000){
				int num = list.size() / 2000 + 1;
				for(int i=0;i < num;i++){
					int toIndex = 2000 * i + 2000;
					if(toIndex > list.size()){
						toIndex = list.size();
					}
					List<String> subList = list.subList(2000 * i, toIndex);
					
					List<GjzLc> tempList = gjzLcMapper.getGjzLcBySituation(subList,address);
					aList.addAll(tempList);
				}
				
			}else{
				if(list.size() >0 ){
					aList = gjzLcMapper.getGjzLcBySituation(list,address);
				}
			}
			return aList;
		}
		
		
		
		return null;
	}

	@Override
	public Map<String,List<AddressMsg>> getKeyVillageDzJwd() {
		
		Map<String,List<AddressMsg>> map = new HashMap<String,List<AddressMsg>>();
		
		List<AddressMsg> a = setKeyVill("A");
		List<AddressMsg> b = setKeyVill("B");
		List<AddressMsg> c = setKeyVill("C");
		
		map.put("kmA", a);
		map.put("kmB", b);
		map.put("kmC", c);
		
		return map;
	}
	
	private List<AddressMsg> setKeyVill(String type){
		List<AddressMsg> ams = new ArrayList<AddressMsg>();
		//获取重点村落
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<VillageColligate> keyVillage = villageColligateMapper.getKeyVillage(type);
		logger.info("获取重点村落 "+type+" ："+keyVillage.size() +"条！");
		if(keyVillage != null){
			for (VillageColligate vill : keyVillage) {
				logger.info("重点村落名称："+vill.getVillageName());
				AddressJwdMsg ajm = gjzDzJwdMapper.getJwdByAddress(vill.getVillageName());
				List<String> value = new ArrayList<String>();
				value.add(ajm.getJd());
				value.add(ajm.getWd());
				value.add(ajm.getCount()+"");

				AddressMsg am = new AddressMsg();
				am.setName(ajm.getName());
				am.setValue(value);
				am.setVillageColligate(MapUtils.allVillageColligate.get(ajm.getName()));
//				AddressMsg am = MapUtils.allDzJwd.get(vill.getVillageName());
				ams.add(am);
				
			}
		}
		return ams;
	}
	@Override
	public List<GjzLc> getGjzLc_ta(String type,String address) throws Exception {
		
		logger.info("获取类型为【"+type+"】的供浆者轮次表");
		List<String> list = null;
		switch (Integer.parseInt(type)) {
		case 0:
			list = MapUtils.allTypeGjzMap.get(GjzType.allGjz);
			break;
		case 1:
			list = MapUtils.allTypeGjzMap.get(GjzType.zhongChengGjz);
			break;
		case 2:
			list = MapUtils.allTypeGjzMap.get(GjzType.fuSuGjz);//gjzAllTypeMapper.getfsJy(date, thisYear, lastYear);
			break;
		case 3:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearCreated);//gjzAllTypeMapper.getNewJy(date, thisYear, lastYear);
			break;
		case 4:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianGjz);//gjzAllTypeMapper.getXmJy(date, thisYear, lastYear);
			break;
		case 5:
			list = MapUtils.allTypeGjzMap.get(GjzType.liuShiGjz);//gjzAllTypeMapper.getLsJy(date, thisYear, lastYear);
			break;
		case 6:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianBeConnect);// gjzAllTypeMapper.getLjJy("1");//休眠中已链接
			break;
		case 7:
			list = MapUtils.allTypeGjzMap.get(GjzType.notConnect);//gjzAllTypeMapper.getLjJy(null);//未链接
			break;
		case 8:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearComed);//gjzAllTypeMapper.getThisYearComed(date,thisYear,"1");//今年进站的人
			break;
		case 9:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearNotComed);//gjzAllTypeMapper.getThisYearComed(date,thisYear,null);//今年未进站的人
			break;
		case 10:
			list = MapUtils.allTypeGjzMap.get(GjzType.xiuMianNotConnect);//休眠中未链接
			break;

		default:
			list = MapUtils.allTypeGjzMap.get(GjzType.thisYearCreated);
			break;
		}
		logger.info("获取类型为【"+type+"】的供浆者【"+list.size()+"】条");
		if(address != null && !"".equals(address)){
			List<String> villProviders = MapUtils.allVillProvider.get(address);
			if(villProviders != null && villProviders.size()>0){
				list = MapUtils.retainList(list, villProviders);
				logger.info("地址为【"+address+"】的供浆者【"+villProviders.size()+"】条，综合的当前地址的此类型的浆员为【"+list.size()+"】条");
			}
		}
		List<GjzLc> aList = new ArrayList<GjzLc>();//
		
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		if(list.size() == 0){
			return aList;
		}else if(list.size() > 2000){
			int num = list.size() / 2000 + 1;
			for(int i=0;i < num;i++){
				int toIndex = 2000 * i + 2000;
				if(toIndex > list.size()){
					toIndex = list.size();
				}
				List<String> subList = list.subList(2000 * i, toIndex);
				
				List<GjzLc> tempList = gjzLcMapper.getGjzLcByProviderNo(subList);
				aList.addAll(tempList);
			}
			
		}else{
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			aList = gjzLcMapper.getGjzLcByProviderNo(list);
		}
		
	
		return aList;
	}

	/* (non-Javadoc)
	 * @see cn.jy.map.service.GjzDzJwdService#getGjzLc(java.lang.String, java.lang.String)
	 */
	@Override
	public List<GjzLc> getGjzLc(String address,String date) throws Exception {
		if(address != null && !"".equals(address)){
			DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
			if(date != null && !"".equals(date)){
				logger.info("获取地区【"+address+"】下面的【"+date+"】登记的老浆员的轮次表");
				date = MapUtils.forMatDate(date);
				List<GjzLc> list = gjzLcMapper.getRegGjzLcByAddress(date, address);
				return list;
			}else{
				logger.info("获取地区【"+address+"】下面的 所有老浆员（建档日期在今天之前的）的轮次表");
				List<String> pList = gjzxxMapper.getProviderByAddress(address);
				pList = MapUtils.removeList(pList, MapUtils.allForgeProviderNo);
				
//				List<GjzLc> list = gjzLcMapper.getGjzLcByAddress(address,null);
				List<GjzLc> list = gjzLcMapper.getGjzLcByProviderNo(pList);
				return list;
			}
		}else{
			if(date == null || "".equals(date)){
				date = MapUtils.getNowOnlyDateFomat1();
				
			}
			logger.info("获取指定日期【"+date+"】下面所有进站人员的轮次表");
			
			//获取指定日期进站的所有浆员
			DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
			List<String> providerNoList = gjzDzJwdMapper.getAllProviderNoByDate(date);
			if(providerNoList != null && providerNoList.size()>0){
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				return gjzLcMapper.getGjzLcByProviderNo(providerNoList);
			}
		}
		return null;
	}

	@Override
	public List<ProviderType> getProviderTypes(String villageName) {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		logger.info("根据村落查询浆员类型人数");
		logger.info("参数villageName"+villageName);
		return gjzDzJwdMapper.getProviderTypes(villageName);
	}



}
